package green.util
/**
 * Created by IntelliJ IDEA.
 * User: hekonsek
 * Date: 2009-12-04
 * Time: 14:32:04
 * To change this template use File | Settings | File Templates.
 */

public class UniqueTimestampIdTest extends GroovyTestCase {

  void testReserialization() {
    // when - new id is created automagically
    def id = new UniqueTimestampId()

    // then - parse second one from the latter
    def idFromSerial = new UniqueTimestampId(id.toString())

    // assert - that inner fields are equals
    assertEquals id.@id, idFromSerial.@id
    assertEquals id.@date, idFromSerial.@date
    // ...that equals() is correct
    assertEquals id, idFromSerial
    // ...and that hash codes are correct
    assertEquals id.hashCode(), idFromSerial.hashCode() 
  }

  void testReserializedMapUsage() {
    // when - new id is created automagically
    def id = new UniqueTimestampId()
    // ...and recrated
    def reserialized = new UniqueTimestampId(id.toString())

    // then - add key/value to map
    def map = [ id : 'foo' ]
    // ...and access it using both keys
    def returnedById = map[id]
    def returnedByreserialized = map[reserialized]

    // assert - that both returned values are equal
    assertEquals returnedById, returnedByreserialized
  }

}